# -*- coding: utf-8 -*-

import logging
# pip install minio
from minio import Minio
import py_global

logger = logging.getLogger(__name__)
if __name__ == '__main__':
    client = Minio('192.168.10.129:9000',
                   access_key='25VFaAEZ2oA7uZIbu7Zz',
                   secret_key='RFeccn07gh3oHR751pHowDXfBPkhRrV8h4vqltuZ',
                   secure=False,
                   )

    bucket_name = 'bucket-name-python'
    bucket_exists = client.bucket_exists(bucket_name)
    object_name = 'object-name-python'
    result = client.fput_object(bucket_name, object_name, 'D:/chchen/project/python/py_project/readme.md', )

    # for i in range(10):
    #     object_name = f'{object_name}-{i}'
    #     result = client.fput_object(bucket_name, object_name, 'D:/chchen/project/python/py_project/readme.md', )
    # client.put_object()
    url = client.presigned_get_object(bucket_name, object_name)
    objects = client.list_objects(bucket_name)
    sorted_objects = sorted(objects, key=lambda x: x.last_modified)
    for obj in sorted_objects:
        logger.info(f'{obj.object_name},{obj.last_modified}')

    stat = client.fget_object(bucket_name, object_name, 'D:/chchen/file/readme.md')
    logger.info(f'stat:{stat}')

    # response = client.get_object(bucket_name, object_name)
    # logger.info(f'{response.data}')

